<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        h1{
            background-color: #fff;
        }
    </style>
</head>
<body>
    <button id="red">红色</button>
    <button id="blue">蓝色</button>
    <button id="pink">粉色</button>
    <button id="green">绿色</button>
    <h1>11111</h1>
    <script>
        var redbox=document.getElementById("red");
        var bluebox=document.getElementById("blue");
        var pinkbox=document.getElementById("pink");
        var greenbox=document.getElementById("green");

        //封装
        function getBgColor(col){
            //直接 document.body 可以获取 body
            document.body.style.backgroundColor=col;
            document.body.style.color=col;
            //....
        }

        redbox.onclick=function(){
            getBgColor("red");
        }
        bluebox.onclick=function(){
            getBgColor("blue");
        }
        pinkbox.onclick=function(){
            getBgColor("pink");
        }
        greenbox.onclick=function(){
            getBgColor("green");
        }
    </script>
</body>
</html>